/**
 * @file
 * @author: vscode
 * @Date: 2018-10-23 22:37:16
 * @Last Modified by: v_xieyejiang
 * @Last Modified time: 2018-12-10 11:35:47
 */

'use strict';

const fs = require('fs');
const path = require('path');
const setRes = require('../utils/setRes');

class Notice {
    static read(req, res) {
        const {isEnable} = req.query;
        if (req.session && req.session.notice) {
            if (String(isEnable)) {
                req.session.notice.isEnable = isEnable;
            }
            setRes(res, 200, req.session.notice);
        }
        else {
            setRes(res, 200, null, 'session.notice is not defined');
        }
    }

    static write(req, res) {
        const {noticeText} = req.query;
        let isEnable = false;
        if (!req.session) {
            req.session = {};
            req.session.notice = {};
        }

        if (!noticeText) {
            isEnable = false;
        }
        else {
            isEnable = true;
        }
        req.session.notice = {
            isEnable,
            noticeText
        };
        setRes(res, 200, req.session.notice);
    }
}

module.exports = Notice;
